package org.example.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.Hidden;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "演示接口", description = "DemoController 示例接口")
@RestController
public class DemoController {
    @Operation(summary = "问候接口", description = "返回 Hello, OpenAPI 3! 字符串")
    @ApiResponses({
        @ApiResponse(responseCode = "200", description = "请求成功，返回问候语"),
        @ApiResponse(responseCode = "500", description = "服务器异常")
    })
    @GetMapping("/hello")
    public String hello(
            @Parameter(description = "用户名", example = "张三")
            @RequestParam(value = "name", required = false) String name) {
        return "Hello, OpenAPI 3!" + (name != null ? (", " + name) : "");
    }

    @Hidden // 隐藏接口，不出现在文档中
    @GetMapping("/hidden")
    public String hidden() {
        return "这个接口不会出现在文档中";
    }
}